<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns="http://www.w3.org/1999/xhtml" xmlns:doc="livcos.org/ns/doc"
	xmlns:dg="livcos.org/ns/doc/diagram" xmlns:src="livcos.org/ns/dev/source"
	xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="livcos.org/ns/xslt/function"
	exclude-result-prefixes="doc dg f xs src">

	<xsl:import href="../../../style/base.xsl"/>
	
	<xsl:variable name="javaDocLink" select="f:entity('/localhost/data/livcos.org/config#doc-link_2', /)"/>
	<xsl:variable name="srcDocLink" select="f:entity('/localhost/data/livcos.org/config#doc-link_1', /)"/>
	
	<xsl:template match="src:path">
		<div id="{@id}">
			<xsl:element name="h{count(ancestor::doc:chapter)+1}">
				<span class="inlineEdit" title="title">
					<xsl:apply-templates select="src:title/node()"/>
				</span>
			</xsl:element>
			<xsl:apply-templates select="* except src:*"/>
			<ol class="src_path_list">
				<xsl:apply-templates select="src:location"/>
			</ol>
		</div>
	</xsl:template>

	<xsl:template match="src:location">
		<li>
			<div id="{@id}" class="src_loc">
				<xsl:variable name="_pts" select="tokenize(@param-types, ' ')"/>
				<xsl:variable name="_pts_non-generic"
					select="for $p in $_pts return replace($p, '&lt;.*&gt;', '')"/>
				<xsl:variable name="_m">
					<xsl:value-of select="@member"/>
					<xsl:text>(</xsl:text>
					<xsl:value-of select="string-join($_pts, ', ')"/>
					<xsl:text>)</xsl:text>
				</xsl:variable>
				<xsl:variable name="_m_non-generic">
					<xsl:value-of select="@member"/>
					<xsl:text>(</xsl:text>
					<xsl:value-of select="string-join($_pts_non-generic, ', ')"/>
					<xsl:text>)</xsl:text>
				</xsl:variable>
				<xsl:variable name="_short">
					<xsl:value-of select="@member"/>
					<xsl:text>(</xsl:text>
					<xsl:for-each select="$_pts_non-generic">
						<xsl:if test="position() > 1">, </xsl:if>
						<xsl:value-of select="tokenize(., '\.')[last()]"/>
					</xsl:for-each>
					<xsl:text>)</xsl:text>
				</xsl:variable>
				<xsl:variable name="sorcerer_frg">
					<xsl:value-of select="@member"/>
					<xsl:text>(</xsl:text>
					<xsl:value-of select="string-join(for $p in $_pts return 'undefined', ',')"/>
					<xsl:text>)</xsl:text>
				</xsl:variable>
				<xsl:variable name="uri" select="concat(replace(@package, '\.', '/'), '/', @type)"/>
				<a href="{$javaDocLink/@url}{$uri}.{$javaDocLink/@ext}#{$_m_non-generic}"
					class="src_loc_title" title="{@package}.{@type}.{$_m}">
					<xsl:value-of select="@type"/>
					<xsl:text>.</xsl:text>
					<xsl:value-of select="$_short"/>
				</a>
				<xsl:text> </xsl:text>
				<span style="font-size: 80%">
					<a href="{$srcDocLink/@url}{$uri}.{$srcDocLink/@ext}#{$sorcerer_frg}"
						title="Show source code of {@package}.{@type}.{$_m}">
						<img src="{$toRootPath}/livcos.org/web/img/external.png"/>
					</a>
				</span>
				<xsl:apply-templates select="* except src:*"/>
			</div>
		</li>
	</xsl:template>

</xsl:stylesheet>
